<?php
/**
 * Created by PhpStorm.
 * User: chen
 * Date: 18-5-27
 * Time: 下午3:00
 */

namespace App\ServiceHandler\Common;


use App\Model\Common\Authority;
use App\User;

class AuthorityUsageService
{
    /**
     * 给用户授权
     * @param $uid
     * @param $authorities
     */
    public static function setUserAuthorities($uid, $authorities){
        $user = User::find($uid);
        if(!empty($user)){
            $user->authorities = serialize($authorities);
            return $user->save();
        }
        return false;
    }

    /**
     * 给职务授权
     * @param $duty_id
     * @param $authorities
     */
    public static function setDutyAuthorities($duty_id, $authorities){

    }

    /**
     * 查询所有权限
     */
    public static function queryAllAuthorities(){
        return Authority::paginate(Authority::per_page());
    }

    /**
     * 查询所有元素权限
     */
    public static function queryAllElementAuthorities(){
        return Authority::where('type', Authority::TYPE_ELEMENT)->paginate(Authority::per_page());
    }


}